package com.xiaofengstu.mcams.web.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xiaofengstu.mcams.annotation.ILog;
import com.xiaofengstu.mcams.dto.BasicResultDTO;
import com.xiaofengstu.mcams.enums.RespStatusEnum;
import com.xiaofengstu.mcams.web.entity.TDept;
import com.xiaofengstu.mcams.web.service.TDeptService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author fengzeng
 * @since 2022-05-07
 */
@RestController
@RequestMapping("/web/dept")
@RequiredArgsConstructor
public class TDeptController {

  private final TDeptService deptService;

  @ILog("获取部门列表")
  @GetMapping("/list")
  public BasicResultDTO<List<TDept>> getDeptListByCampId(@RequestParam("campusId") Integer campusId) {
    return new BasicResultDTO(RespStatusEnum.SUCCESS, deptService.list(new QueryWrapper<TDept>().eq("campus_id", campusId)));
  }

  @ILog("通过角色获取部门列表")
  @GetMapping("/listByRole")
  public BasicResultDTO<List<TDept>> getDeptListByRole() {
    return new BasicResultDTO<>(RespStatusEnum.SUCCESS, deptService.listByRole());
  }

}
